﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Com.Toook.ParseHtml.Entity
{
    /// <summary>
    /// 分类页面的一条解析规则。一个页面可以有多个解析规则
    /// </summary>
    public class Rule
    {
        //public string EntityName;
        /// <summary>
        /// 当前步骤
        /// </summary>
        public Step CurrentStep
        {
            get{ return currentStep;}            
        }
        
        /// <summary>
        /// 获取最终链接步骤
        /// </summary>
        public Property CurrentProperty
        {
            get{ return currentProperty; }            
        }
        /// <summary>
        /// 增加步骤
        /// </summary>
        /// <param name="step"></param>
        public void AddStep(Step step)
        {
            stepList.Add(step);
        }
        /// <summary>
        /// 增加详细页面 a href 解析步骤
        /// </summary>
        /// <param name="step"></param>
        public void AddProperty(Property property)
        {
            propertyList.Add(property);
        }
        /// <summary>
        /// 移到下一步.开始位置在所有步骤之前，就像DataReader.Read()
        /// </summary>
        /// <returns></returns>
        public bool NextStep()
        {
            index++;
            if(index < stepList.Count)
            {
                currentStep = stepList[index];
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 移到下一步.开始位置在所有Property之前，就像DataReader.Read()
        /// </summary>
        /// <returns></returns>
        public bool NextProperty()
        {
            indexProperty++;
            if (indexProperty < propertyList.Count)
            {
                currentProperty = propertyList[indexProperty];
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 重置Step的位置
        /// </summary>
        public void ResetNextStep()
        {
            index = -1;
        }
        /// <summary>
        /// 重置Property的位置
        /// </summary>
        public void ResetNextProperty()
        {
            indexProperty = -1;
        }
        public Rule()
        {          
        }
        
        private int index = -1;
        private int indexProperty = -1;
        private Step currentStep = null;
        private Property currentProperty = null;
        private List<Step> stepList = new List<Step>();
        private List<Property> propertyList = new List<Property>();
        //private Leaf leaf = null;
        ///// <summary>
        ///// 链接、图片等页节点的解析规则
        ///// </summary>
        //public Leaf MultiLeaf
        //{
        //    get
        //    {
        //        return leaf;
        //    }
        //    set
        //    {
        //        leaf = value;
        //    }
        //}
    }
}
